package com.linzhaowei.headhuntingservice;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.linzhaowei.headhuntingservice.fragment.ApplicantJobInformationFragment;
import com.linzhaowei.headhuntingservice.fragment.ApplicantPersonalFragment;
import com.linzhaowei.headhuntingservice.fragment.EMChatFragment;

/**
 * 求职者主界面
 */
public class ApplicantMain extends AppCompatActivity implements View.OnClickListener {

    private Button jobInformation;
    private Button message;
    private Button personal;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_applicantmain);

        replaceFragment(new ApplicantJobInformationFragment());
        initViews();
        setEvents();
    }


    /**
     * 绑定组件
     */
    private void initViews() {
        jobInformation = findViewById(R.id.a_job_information);
        message = findViewById(R.id.a_message);
        personal = findViewById(R.id.a_personal);
    }

    /**
     * 绑定事件
     */
    private void setEvents() {
        jobInformation.setOnClickListener(this);
        message.setOnClickListener(this);
        personal.setOnClickListener(this);
    }

    /**
     * 点击事件
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.a_job_information:
                replaceFragment(new ApplicantJobInformationFragment());
                break;

            case R.id.a_personal:
                replaceFragment(new ApplicantPersonalFragment());
                break;
            case R.id.a_message:
                replaceFragment(new EMChatFragment());
                break;
            default:
                break;
        }

    }


    /**
     * 刷新Fragment界面
     *
     * @param fragment
     */
    private void replaceFragment(Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.up_layout, fragment);
        transaction.commit();
    }


}
